1. Field of the Invention
The present invention relates generally to an image data encoding apparatus for variable-length-encoding image data to generate compressed image data and, more particularly, to control of total code quantity of the compressed image data generated through a block encoding process.
2. Description of the Related Art
Various image-data compression methods are proposed to efficiently transmit and store image data. JPEG (Joint Photographic Expert Group) proposes a method for encoding internationally-standardized image data as one of the methods. The JPEG encoding method is referred to as "JPEG algorithm" and is widely used for image data processing in a CD-ROM system and the like.
In the case of the JPEG algorithm, one screen Sc is encoded every B11 to Bmn blocks, each of which comprises 8.times.8 pixels as shown in FIG. 1. Each block includes data corresponding to 64 (8 rows.times.8 columns) pixels P11 to P88.
FIG. 2 shows an encoding circuit following the JPEG algorithm, that is, a JPEG encoder includes a DCT arithmetic circuit 1, a quantization circuit 2, an encoding circuit 3, a threshold value table 4, and a Huffman code table 5.
The DCT arithmetic circuit 1 receives image data in units of blocks and generates 64 DCT coefficient data values by applying two-dimensional discrete cosine transform (DCT) to each block. The quantization circuit 2 receives the 64 DCT coefficient data values from the DCT arithmetic circuit 1 and quantizes the 64 DCT coefficient data values while referring to threshold values stored in the threshold value table 4. A threshold value determines the compression rate of image data or the quality of a reproduced image and it is optionally set in accordance with the purpose for using an apparatus. The encoding circuit 3 receives quantized DCT coefficient data from the quantization circuit 2 and performs variable-length-encoding of the quantized DCT coefficient data in accordance with Huffman codes stored in the Huffman code table 5 to generate compressed image data. A Huffman code is a variable-length code assigned to each quantized DCT coefficient data value in accordance with the appearance frequency of an expected DCT coefficient data value. That is, a short code is assigned to a DCT coefficient data value having a high appearance frequency.
FIG. 3 shows the frequency components for a plurality of DCT coefficient data values, generated through DCT arithmetic processing for each block of the DCT arithmetic circuit 1. At this time, as shown in FIG. 3, DCT coefficient data having a low frequency component is arranged at the left top of a block BL and DCT coefficient data having a high frequency component is arranged at the right bottom of the block BL. The encoding circuit 3 first encodes the quantized DCT coefficient data present at the left top end and then encodes each DCT coefficient data value while performing zigzag scanning in the diagonal direction. Finally, the quantized DCT coefficient data present at the right bottom end is encoded. In this case, a total code quantity of the compressed image data in one block is limited to a predetermined upper limit value. Therefore, encoding is limited so that the total code quantity does not exceed the upper limit value. For example, the JPEG encoder is configured to count the number of codes of code data (compressed imaged data) supplied from the encoding circuit 3 and supply a signal indicating the interruption of encoding process to the encoding circuit 3 before the total code quantity exceeds the upper limit value.
In the case of normal encoding process, several code data values are simultaneously output from the encoding circuit 3. Therefore, as shown in FIG. 3, when encoding of a DCT coefficient data value Da is completed, the JPEG encoder estimates total code quantity when encoding of a DCT coefficient data value Db is completed. The data value Db occurs after the DCT coefficient data value Da at intervals of several data values. The JPEG encoder determines whether the estimated total code quantity exceeds the upper limit value. When the total code quantity does not exceed the upper limit value, the JPEG encoder allows output of the code data of the DCT coefficient data value Db. However, when the total code quantity exceeds the upper limit value, the JPEG encoder limits the outputs of the code data for the DCT coefficient data values present after the DCT coefficient data value Da and supplies an End-Of-Block (EOB) code to the encoding circuit 3.
However, the above interruption of encoding processing allows truncation of some DCT coefficient data values (high-frequency components in the case of the above example) in one block. As a result, when compressed image data is extended, complete original image data is not able to be reproduced. This deteriorates the image quality of a reproduced screen.
One method to minimize the deterioration of the image quality is to encode the image data on one screen again at a high compression rate when a total code quantity of one block exceeds the upper limit value. When the total code quantity of compressed image data output from the encoding circuit 3 exceeds the upper limit value, the JPEG decoder changes threshold values of the quantization circuit 2 in accordance with the excessive quantity. The quantization circuit 2 performs quantization by using a changed threshold value. In the case of this method, it is necessary to encode the image data for one screen twice. As a result, the encoding time undesirably increases. In the case of moving pictures of a television signal (NTSC system) or the like, a screen comprising 30 frames is continuously supplied in one second. As a result, the image encoding speed may be slower than the screen supply speed.
Thus there is a need for improved high-speed encoding methods for image data.